// TODO: CODE REVIEW & CLEANUP!
//
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using HomeUX.ClientAppSupport;
using HomeUX.SimulationOnClient;

namespace HomeUX.ClientApp
{

public partial class Page : UserControl
{
    /// <summary>
    /// Indicates if the initial <n>SizeChanged</n> event has been received.
    /// </summary>
    bool _initialSizeChanged = false;

    public Page()
	{
        // Required to initialize variables
        InitializeComponent();

        // hook up events
        //Loaded += Page_Loaded;

        SizeChanged += delegate
        {
            if (!_initialSizeChanged)
            {
                _initialSizeChanged = true;
                OnPageFullyLoaded();
            }
        };
	}

    void OnPageFullyLoaded()
    {
        // initialize the client framework -- see ClientFramework for documentation
        ClientFramework.Current = new ClientFramework()
        {
            StartupEventArgs = App.Current.StartupEventArgs,
            TopLevelPage = this,
            TopLevelPageTransform = PageTransform,
            TopLevelPageLayoutRoot = LayoutRoot,
			ScreenChooser = ScreenChooser,
			ScreenArea = ScreenArea,
            HomeButton = HomeButton,
            BackButton = BackButton,
            ClientStatus = ClientStatus,
            AutoRepeatDelay = TimeSpan.FromSeconds(0.5),
            AutoRepeatInterval = TimeSpan.FromSeconds(0.2),
            DefaultHomeScreenName = "LivingAreaScreen",
			DefaultBackgroundBrush =
				(Brush)Application.Current.Resources["DefaultBackgroundBrush"],
            ServerSimulator = new ServerSimulator()
		};
    }
}

}
